package com.lindroid.controller

import com.lindroid.entity.Resource
import com.lindroid.entity.User
import com.mit.entity.FindResult
import com.mit.entity.RespResult
import org.springframework.beans.BeanUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.*


@RestController
class UserController {

    @Autowired
    lateinit var resource: Resource

    /**
     * 在浏览器中输入http://localhost:8080/user
     */
    @RequestMapping("/user")
    fun user() = FindResult(data = User("Lin", "123456", 30, Date(), "一个好人"))

    @RequestMapping("/user2")
    fun user2() = FindResult(data = User("Lin", "123456", 30, Date(), ""))

    /**
     * 将资源配置信息映射到实体类
     */
    @RequestMapping("/resource")
    fun getResource(): FindResult {
        val bean = Resource()
        println("bean=$bean")
        println("resource=$resource")
        BeanUtils.copyProperties(resource, bean) //拷贝属性
        return FindResult(data = bean)
    }
}